package com.itheima.Jiuye15;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(1000);
        Socket accept = serverSocket.accept();   //监听客户端连接
        InputStream ips = accept.getInputStream();
        int a;
        while ((a= ips.read()) != -1){
            System.out.print((char) a);
        }
        BufferedWriter bfw = new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
        bfw.write("你是谁");
        bfw.newLine();
        bfw.flush();

        accept.shutdownOutput();

        serverSocket.close();
        bfw.close();
        ips.close();
        accept.close();
    }
}
